package com.prs.crm.action.hr.report;

import java.util.Collection;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;
import org.courser.ui.PaginationSupport;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Restrictions;

import com.prs.crm.action.ReportAction;
import com.prs.crm.context.Constrains;
import com.prs.crm.domain.hr.Train;
import com.prs.crm.report.ChartResult;
import com.prs.crm.report.ChartService;
import com.prs.crm.report.ExportConfig;
import com.prs.crm.report.ReportCell;
import com.prs.crm.report.ReportTable;
import com.prs.crm.report.ReportUtils;
import com.prs.crm.service.hr.TrainService;

public class PersonTrainReportAction extends ReportAction {

	private static final long serialVersionUID = -8307485186412770899L;
	
	private TrainService trainService;
	private ChartResult chartResult;
	private ChartService chartService;
	private PaginationSupport pagination;
	private String category;
	private int exportType;
	
	@Action("editPersonTrain")
	public String editPersonTrain(){
		
		return SUCCESS;
	}
	@Action(value = "viewPersonTrainPie", results = { @Result(name = "success", type = "chain", location = "editPersonTrain") })
	public String viewPersonTrainPie(){
		Collection<?> dataList = this.getTrainService().getReportPersonTrainSource();
		chartResult = this.getChartService().export(this.getTrainService().fillDataset(dataList, Constrains.REPORT_PIECHART), "人员培训统计分析", "listReportPersonTrain");
		return SUCCESS;
	}
	@Action(value = "viewPersonTrainBar", results = { @Result(name = "success", type = "chain", location = "editPersonTrain") })
	public String viewPersonTrainBar(){
		Collection<?> dataList = this.getTrainService().getReportPersonTrainSource();
		chartResult = this.getChartService().export(this.getTrainService().fillDataset(dataList, Constrains.REPORT_BARCHART), "人员培训统计分析", "数量", "", "listReportPersonTrain");
		return SUCCESS;
	}
	@Action("listReportPersonTrain")
	public String listReportPersonTrain(){
		category = ReportUtils.URLDecode(this.getCategory());
		DetachedCriteria criteria = this.getPaginationHelper().createQuery(
				Train.class);
		criteria.createAlias("item", "rk");
		criteria.add(Restrictions.eq("rk.name", category));
		pagination = this.getPaginationHelper().prepare(pagination);
		this.setPagination(this.getTrainService().listByPage(criteria,
				pagination));
		return SUCCESS;
	}
	
	@Action(value = "exportPersonTrainReport", results = { @Result(name = "success", type = "stream", params = {
			"contentType", "${contentType}", "inputName", "inputStream",
			"bufferSize", "1024", "contentDisposition",
			"filename=${outfileName}" }) })
	public String exportPersonTrainReport(){
		ReportTable table = new ReportTable("人员培训统计分析报表");
		table.addCell(new ReportCell("序号","id"));
		table.addCell(new ReportCell("标题","title"));
		table.addCell(new ReportCell("档案编号","code"));
		table.addCell(new ReportCell("培训项目","item.name"));
		table.addCell(new ReportCell("培训课时","perid"));
		DetachedCriteria criteria = this.getPaginationHelper().createQuery(
				Train.class);
		criteria.createAlias("item", "rk");
		criteria.add(Restrictions.eq("rk.name", this.getCategory()));
		this.setOutFilePath(this.getReportService().report(criteria, table,
				new ExportConfig(), this.getExportType()));
		return SUCCESS;
	}
	public TrainService getTrainService() {
		return trainService;
	}
	public void setTrainService(TrainService trainService) {
		this.trainService = trainService;
	}
	public ChartResult getChartResult() {
		return chartResult;
	}
	public void setChartResult(ChartResult chartResult) {
		this.chartResult = chartResult;
	}
	public ChartService getChartService() {
		return chartService;
	}
	public void setChartService(ChartService chartService) {
		this.chartService = chartService;
	}
	public PaginationSupport getPagination() {
		return pagination;
	}
	public void setPagination(PaginationSupport pagination) {
		this.pagination = pagination;
	}
	public String getCategory() {
		return category;
	}
	public void setCategory(String category) {
		this.category = category;
	}
	public int getExportType() {
		return exportType;
	}
	public void setExportType(int exportType) {
		this.exportType = exportType;
	}
	
	
	
	
	
	
	
	
	
}
